﻿using System;

namespace WebTest.Core.Entities.OrderAggregate
{
    public class OrderItem : BaseEntity
    {
        /// <summary>
        /// 商品名称
        /// </summary>
        public string Name { get; private set; }
        /// <summary>
        /// 商品的单价
        /// </summary>
        public decimal Price { get; private set; }
        /// <summary>
        /// 商品的数量
        /// </summary>
        public int Amount { get; private set; } = 1;
        public decimal TotalPrice
        {
            get
            {
                return Price * Amount;
            }
        }
        public OrderItem(string name, decimal price, int amount = 1)
        {
            Name = name ?? throw new ArgumentNullException(nameof(name));
            Price = price;
            Amount = amount;
        }
        public void SetAmount(int amount)
        {
            Amount = amount != 0 ? 
                amount : 
                throw new ArgumentOutOfRangeException(nameof(amount));
        }
    }
}
